﻿Imports System.Net.Mail
Partial Class WebForm_ManageWorkHeader
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            '判斷是否有找到
            If DirectCast(Master.FindControl("lblHeadText"), Label) IsNot Nothing Then
                DirectCast(Master.FindControl("lblHeadText"), Label).Text = Me.GetLocalResourceObject("Title.Text")
            End If

            '判斷是否為結案案件
            Dim Type As String = Me.Request.QueryString("Type")
            If Type <> "" Then
                Me.MailTabPanel.HeaderText = Me.GetLocalResourceObject("CloseCase")
                Me.SearchWorkHeader1.IsClose = True
                Me.HandleWorkHeader1.IsClose = True
            Else
                Me.MailTabPanel.HeaderText = Me.GetLocalResourceObject("HandleCase")
                Me.SearchWorkHeader1.IsClose = False
                Me.HandleWorkHeader1.IsClose = False
            End If

            '判斷目前使用者狀態
            Me.MyOrganizationID = clsAuth.GetOrganizationID(clsAuth.GetUserID())
            Me.HandleWorkHeader1.MyOrganizationID = Me.MyOrganizationID
            If clsAuth.IsEnvirPerson(MyOrganizationID) Then
                '環保局人員
                Me.HandleWorkHeader1.MyType = "1"
                Me.SearchWorkHeader1.MyType = "1"
            ElseIf clsAuth.IsRoadPerson(MyOrganizationID) Then
                '工務段人員
                Me.HandleWorkHeader1.MyType = "3"
                Me.SearchWorkHeader1.MyType = "3"
            ElseIf clsAuth.GetUserID() <> "" Then
                '公所人員
                Me.HandleWorkHeader1.MyType = "2"
                Me.SearchWorkHeader1.MyType = "2"
            Else
                '一般民眾
                Me.HandleWorkHeader1.MyType = ""
                Me.SearchWorkHeader1.MyType = ""
            End If
        End If
    End Sub

    Protected Sub SearchWorkHeader_RowUpdating(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchWorkHeader1.RowUpdating
        '單筆檢視模式
        Me.MultiView1.SetActiveView(vwHandleWorkHeader)
        Me.HandleWorkHeader1.DataAccessMode = My.DataAccessMode.Update
        Me.HandleWorkHeader1.InitData(Me.SearchWorkHeader1.FindDirtyHeaderID, "")
    End Sub

    Protected Sub HandleWorkHeader1_Back(ByVal sender As Object, ByVal e As System.EventArgs) Handles HandleWorkHeader1.back
        '列表檢視模式
        Me.MultiView1.SetActiveView(vwSearchWorkHeader)
    End Sub

    Protected Sub HandleWorkHeader1_Finish(ByVal sender As Object, ByVal e As System.EventArgs) Handles HandleWorkHeader1.Finish
        '列表檢視模式
        Me.MultiView1.SetActiveView(vwSearchWorkHeader)
        Me.SearchWorkHeader1.BindGV()
    End Sub
End Class

Partial Class WebForm_ManageWorkHeader
    Protected Sub SearchWorkHeader_RowDeleting(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchWorkHeader1.RowDeleting
        Dim dat As New clsData
        Dim sql As New StringBuilder
        Using scope As New Transactions.TransactionScope
            sql.Length = 0
            sql.AppendFormat("Delete FindDirtyHeader ")
            sql.AppendFormat(" where FindDirtyHeaderID='{0}' ", Me.SearchWorkHeader1.FindDirtyHeaderID)
            dat.AccData(sql)
            sql.Length = 0
            sql.AppendFormat("Delete FindDirtyItem ")
            sql.AppendFormat(" where FindDirtyHeaderID='{0}' ", Me.SearchWorkHeader1.FindDirtyHeaderID)
            dat.AccData(sql)
            scope.Complete()
        End Using
        Me.SearchWorkHeader1.BindGV()
    End Sub

    '登入者組織編號
    Public Property MyOrganizationID() As String
        Get
            Return ViewState("MyOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("MyOrganizationID") = value
        End Set
    End Property
End Class